class ChatContentExpression extends ComponentEx {

    private img_expression: eui.Image;

    private index: number = 1;

    public constructor() {
        super();

        this.skinName = 'ChatContentExpressionSkin';
    }

    childrenCreated() {
        super.childrenCreated();

        this.touchEnabled = false;
        this.touchChildren = false;
    }

    update(data: any, x: number, y: number) {

        this.play(data.id);

        egret.setTimeout(this.hide, this, 3000);

        this.show();

        this.x = x - this.width / 2;
        this.y = y - this.height / 2;
    }

    show() {
        super.show();

        gameManager.layerManager.topLayer.addChild(this);
    }

    hide() {
        super.hide();

        gameManager.layerManager.topLayer.removeChild(this);
    }

    private play(id: number) {

        this.img_expression.source = "expression" + id + "." + this.index;

        let thiz = this;
        egret.setTimeout(function () {
            thiz.index = thiz.index == 1 ? 2 : 1;
            thiz.play(id);
        }, this, 200);
    }
}